package com.lzy.product.service.impl;

import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.AgentOrderYieldRatioMapperExt;
import com.lzy.product.dtos.agent.AgentOrderYieldRatioDto;
import com.lzy.product.entity.AgentOrderYieldRatio;
import com.lzy.product.service.AgentOrderYieldRatioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2018/4/27.
 */
@Service
public class AgentOrderYieldRatioServiceImpl implements AgentOrderYieldRatioService {

    @Autowired
    AgentOrderYieldRatioMapperExt agentOrderYieldRatioMapperExt;

    @Override
    public Long insert(AgentOrderYieldRatioDto dto) {
        AgentOrderYieldRatio agentOrderYieldRatio = DozerUtils.map(dto, AgentOrderYieldRatio.class);
        return agentOrderYieldRatioMapperExt.insertSelective(agentOrderYieldRatio) > 0 ? agentOrderYieldRatio.getId() : null;
    }

    @Override
    public Boolean update(AgentOrderYieldRatioDto dto) {
        return agentOrderYieldRatioMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, AgentOrderYieldRatio.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return null;
    }

    @Override
    public Boolean remove(Long id) {
        return null;
    }

    @Override
    public AgentOrderYieldRatioDto findById(Long id) {
        return null;
    }

    @Override
    public List<AgentOrderYieldRatioDto> query(AgentOrderYieldRatioDto dto) {
        if (dto.getDeleted() == null)
            dto.setDeleted(false);
        return agentOrderYieldRatioMapperExt.query(dto);
    }

    @Override
    public List<AgentOrderYieldRatioDto> queryAgencyIncome() {
        return DozerUtils.maps(agentOrderYieldRatioMapperExt.queryAgencyIncome(), AgentOrderYieldRatioDto.class);
    }

    @Override
    public AgentOrderYieldRatioDto selectByOrderId(Long orderId) {
        AgentOrderYieldRatioDto agentOrderYieldRatioDto = new AgentOrderYieldRatioDto();
        agentOrderYieldRatioDto.setOrderId(orderId);
        List<AgentOrderYieldRatioDto> list = agentOrderYieldRatioMapperExt.query(agentOrderYieldRatioDto);
        if (list != null && list.size() == 1) {
            return DozerUtils.map(list.get(0), agentOrderYieldRatioDto.getClass());
        }
        return null;
    }
}
